<template>
    <div class="list">
        <el-form ref="form" :model="list" label-width="40px">
            <el-form-item label="名称">
                <el-input v-model="list.name"></el-input>
            </el-form-item>
            <el-form-item label="价格">
                <el-input v-model="list.price"></el-input>
            </el-form-item>
            <el-upload
                    action="http://localhost:3000/api/upload"
                    list-type="picture-card"
                    class="uploadimg"
                    :on-preview="handlePreview"
                    :on-remove="handleRemove"
                    :on-success="handleSuccess"
                    :on-error="handleError">
                <i class="el-icon-plus"></i>
            </el-upload>
            <el-dialog :visible.sync="dialogVisible">
                <img width="100%" :src="dialogImageUrl" alt="">
            </el-dialog>
            <el-form-item>
                <el-button type="primary" @click="uploadList">立即创建</el-button>
                <el-button>取消</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>

<script>
    import axios from 'axios'
    export default {
        name: "createList",
        data() {
            return {
                dialogImageUrl: '',
                dialogVisible: false,
                list:{
                    name:'',
                    price:'',
                    imgUrl:''
                }
            };
        },
        methods: {
           //图片上传成功的回调
            handleSuccess(res, file, fileList){
                console.log(res);
            },
            //上传失败
            handleError(err, file, fileList) {
                this.$notify({
                    title: "失败",
                    message: "上传失败",
                    type: "warning",
                    duration: 2000
                });
            },
            handleRemove(file, fileList) {
                console.log(file, fileList);
            },
            handlePreview(file) {
                console.log(file);
            },
            uploadList(){}
        }
    }
</script>

<style scoped>
.list{
    width: 100%;
}
.uploadimg{
    margin: 20px 40px;
}
</style>